//
//  HomeAdAlertVCViewController.m
//  ImGuider
//
//  Created by llt on 2017/9/8.
//  Copyright © 2017年 AudioCtrip. All rights reserved.
//

#import "HomeAdAlertVCViewController.h"

#define angle2Radio(angle) ((angle) * M_PI / 180.0) 

@interface HomeAdAlertVCViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *firstCityLogo;
@property (weak, nonatomic) IBOutlet UIImageView *secondCityLogo;

@end

@implementation HomeAdAlertVCViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
    
    [self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(userTapAction)]];
}
- (void)viewDidAppear:(BOOL)animated {
    
    [super viewDidAppear:animated];
    
    [self setanimationWithView2:self.firstCityLogo];
    [self setanimationWithView2:self.secondCityLogo];
}

- (void)setanimationWithView:(UIView *)view {
    
    CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
    
    anim.keyPath = @"transform.rotation";  // rotation.x、rotation.y与rotation.z 默认是z
    anim.values = @[@(angle2Radio(-5)), @(angle2Radio(5)), @(angle2Radio(-5))]; // 把度数转换为弧度  度数/180*M_PI
    anim.repeatCount = MAXFLOAT;    // 动画执行次数无限次
    
    [view.layer addAnimation: anim forKey: nil];
}

- (void)setanimationWithView2:(UIView *)view {
    
    CABasicAnimation *anim = [CABasicAnimation animation];
    
    anim.keyPath = @"transform.scale";  // transform.scale 表示长和宽都缩放
    anim.toValue = @0.8;                  // @0 缩放到最小
    anim.duration = 0.5;                // 设置动画执行时间
    anim.repeatCount = MAXFLOAT;        // MAXFLOAT 表示动画执行次数为无限次
    
    anim.autoreverses = YES;            // 控制动画反转 默认情况下动画从尺寸1到0的过程中是有动画的，但是从0到1的过程中是没有动画的，设置autoreverses属性可以让尺寸0到1也是有过程的
    
    [view.layer addAnimation: anim forKey: nil];
}

- (void)showWithVC:(UIViewController *)vc {
    
    self.modalPresentationStyle = UIModalPresentationOverCurrentContext|UIModalPresentationFullScreen;
    [vc presentViewController:self animated:YES completion:nil];
}

- (void)userTapAction {
    
    [self dissmissVC:nil];
    
//    NSInteger tag = sender.tag;
//
//    if (tag == 0) { // 卢浮宫
//
//        [_delegate selectScenicID:@"fae6a345-5967-47ea-a455-dcaf40c8425f"];
//
//    } else if (tag == 1) { // 伦敦
//
//        [_delegate selectCityID:@(19).stringValue];
//
//    } else if (tag == 2) { // 注册
    // [_delegate loginActionTapped];
//    }
    
    [_delegate loginActionTapped];
}

- (IBAction)dissmissVC:(UIButton *)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
